/**
 * 这个js主要封装任何框架可以通用的dom 操纵
 */
$(function() {
	/**
	 * 统一处理number 类型的input maxlength 不管用的问题
	 */
	$(document).on('input change propertychange', 'input[type="number"]', function(index, dom) {
		var $this = $(this);
		var maxlength = Number($this.attr("maxlength"));
		if (!isNaN(maxlength) && (maxlength + "").length > 0) {
			// oninput="if(value.length>5)value=value.slice(0,5)"
			var value = $this.val();
			if (value.length > maxlength) {
				$this.val(value.slice(0, maxlength));
			}
		}
	});
	/**
	 * 统一截字 默认截字40 超过+..
	 */
	$(".boot-substring").each(function() {
		var $this = $(this);
		var sustring = $this.attr("substring");
		if (!sustring) { // 如果存在额外属性 则截断额外的，否则
			sustring = 40;
		}
		var text = $this.text();
		if (text && text.length > sustring) {
			try {
				text = text.substring(0, sustring) + "...";
			} catch (e) {
				text = $this.text();
			}

		}
		$this.text(text);
	});

});
// ie8下支持数组的 filter
if (!Array.prototype.filter) {
	Array.prototype.filter = function(fun /* , thisp */) {
		"use strict";

		if (this === void 0 || this === null)
			throw new TypeError();

		var t = Object(this);
		var len = t.length >>> 0;
		if (typeof fun !== "function")
			throw new TypeError();

		var res = [];
		var thisp = arguments[1];
		for (var i = 0; i < len; i++) {
			if (i in t) {
				var val = t[i]; // in case fun mutates this
				if (fun.call(thisp, val, i, t))
					res.push(val);
			}
		}

		return res;
	};
}
// 兼容以前版本的 Function 对象也支持 bind 函数
/*Function.prototype.bind = function(oThis) {
	if (typeof this !== "function") {
		throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
	}

	var aArgs = Array.prototype.slice.call(arguments, 1), fToBind = this, fNOP = function() {
	}, fBound = function() {
		return fToBind.apply(this instanceof fNOP  ? this : oThis || window, aArgs.concat(Array.prototype.slice.call(arguments)));
	};

	fNOP.prototype = this.prototype;
	fBound.prototype = new fNOP();

	return fBound;
};*/